package com.lovo.bbs.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.naming.NamingException;

import com.lovo.bbs.po.LoginPo;
import com.lovo.bbs.util.DbUtil;
import com.lovo.bbs.util.MysqlDb;

/**
 * 登录Dao
 * 
 * @author tiancen2001
 * 
 */
public class LoginDao {
    public LoginDao(){
    	
    }
	/**
	 * 登录校验
	 * 
	 * @param loginpo
	 * @return
	 * @throws NamingException
	 * @throws SQLException
	 */
	public  boolean checkUser(LoginPo loginpo, int type)
			throws NamingException, SQLException {
		boolean isUser = false;
		MysqlDb mysqldb = new MysqlDb();
		mysqldb.setPool(true);
		Connection con = DbUtil.getConn(mysqldb);

		String sql = "select password   from user where username=? and usertype>=?";

		PreparedStatement ps = con.prepareStatement(sql);
		ps.setString(1, loginpo.getUserName());
		ps.setInt(2, type);
		ResultSet rs = ps.executeQuery();
		if (rs.next()) {
			if (rs.getString(1).equals(loginpo.getUserPassword())) {
				isUser = true;
			}
		}
		mysqldb.closePS(ps);
		mysqldb.closeRS(rs);
		mysqldb.closeConnection(con);
		return isUser;
	}
}
